<?php

/**
 * This is for search user settings.
 */
class Validations_Searchforusersettings {

    /**
     * 
     * @param type $propertyDetails
     * @param type $userSearchDetails
     * @return boolean
     */
    public function search($propertyDetails, $userSearchDetails) {
        $cityMatched = $this->isCityMatched($propertyDetails->city, $userSearchDetails->city);
        $stateMatched = $this->isStateMatched($propertyDetails->state, $userSearchDetails->state);
        $zipMatched = $this->isZipCodeMatched($propertyDetails->zipcode, $userSearchDetails->zipcode);
        $propertyTypeMatched = $this->isPropertyTypeMatched($propertyDetails->propertyType, $userSearchDetails->propertyType);
        $rentalPeriodMatched = $this->isRentalPeriodMatched($propertyDetails->rentalPeriod, $userSearchDetails->rentalPeriod);
        $furnishTypeMatched = $this->isFurnishTypeMatched($propertyDetails->furnishType, $userSearchDetails->furnishType);
        $roomsMatched = $this->isRoomMatched($propertyDetails->rooms, $userSearchDetails->rooms);
        $areaMatched = $this->isAreaMatched($propertyDetails->area, $userSearchDetails->area);
        $rentMatched = $this->isRentMatched($propertyDetails->rent, $userSearchDetails->rent);

        if ($cityMatched || $stateMatched || $zipMatched || $propertyTypeMatched || $rentalPeriodMatched || $furnishTypeMatched || $roomsMatched || $areaMatched || $rentMatched) {
            return true;
        }
        return false;
    }

    /**
     * 
     * @param type $compareValue
     * @param type $value1
     * @param type $value2
     */
    public function isBetween($compareValue, $value1, $value2) {
        $isBetween = false;
        if ($compareValue >= $value1 && $compareValue <= $value2) {
            $isBetween = true;
        }
        return $isBetween;
    }

    /**
     * 
     * @param type $value1
     * @param type $value2
     * @return boolean
     */
    public function isEqual($value1, $value2) {
        if ($value1 == $value2) {
            return true;
        }
        return false;
    }

    /**
     * 
     * @param type $propertyCity
     * @param type $userCityArray
     * @return boolean
     */
    public function isCityMatched($propertyCity, $userCityArray) {
        $matched = false;
        foreach ($userCityArray as $ucity) {
            if ($this->isEqual($ucity, $propertyCity)) {
                $matched = true;
            }
        }
        return $matched;
    }

    /**
     * 
     * @param type $propertyState
     * @param type $userStateArray
     * @return boolean
     */
    public function isStateMatched($propertyState, $userStateArray) {
        $matched = false;
        foreach ($userStateArray as $ustate) {
            if ($this->isEqual($ustate, $propertyState)) {
                $matched = true;
            }
        }
        return $matched;
    }

    /**
     * 
     * @param type $propertyZipcode
     * @param type $userZipArray
     * @return boolean
     */
    public function isZipCodeMatched($propertyZipcode, $userZipArray) {
        $matched = false;
        foreach ($userZipArray as $uzip) {
            if ($this->isEqual($uzip, $propertyZipcode)) {
                $matched = true;
            }
        }
        return $matched;
    }

    /**
     * 
     * @param type $propertyType
     * @param type $userPropertyTypeArray
     * @return boolean
     */
    public function isPropertyTypeMatched($propertyType, $userPropertyTypeArray) {
        $matched = false;
        foreach ($userPropertyTypeArray as $utype) {
            if ($this->isEqual($utype, $propertyType)) {
                $matched = true;
            }
        }
        return $matched;
    }

    /**
     * 
     * @param type $propertyRentalPeriod
     * @param type $userRentalPeriodArray
     * @return boolean
     */
    public function isRentalPeriodMatched($propertyRentalPeriod, $userRentalPeriodArray) {
        $matched = false;
        foreach ($userRentalPeriodArray as $uperiod) {
            if ($this->isEqual($uperiod, $propertyRentalPeriod)) {
                $matched = true;
            }
        }
        return $matched;
    }

    /**
     * 
     * @param type $propertyFurnishType
     * @param type $userFernishTypeArray
     * @return boolean
     */
    public function isFurnishTypeMatched($propertyFurnishType, $userFernishTypeArray) {
        $matched = false;
        foreach ($userFernishTypeArray as $utype) {
            if ($this->isEqual($utype, $propertyFurnishType)) {
                $matched = true;
            }
        }
        return $matched;
    }

    /**
     * 
     * @param type $propertyRooms
     * @param type $userRooms
     * @return type
     */
    public function isRoomMatched($propertyRooms, $userRooms) {
        return $this->isEqual($userRooms, $propertyRooms);
    }

    /**
     * 
     * @param type $propertyArea
     * @param type $userArea
     * @return type
     */
    public function isAreaMatched($propertyArea, $userArea) {
        return $this->isEqual($userArea, $propertyArea);
    }

    /**
     * 
     * @param type $propertyRent
     * @param type $userRent
     * @return type
     */
    public function isRentMatched($propertyRent, $userRent) {
        return $this->isEqual($userRent, $propertyRent);
    }

}